;version 0.1.6.27



#SingleInstance force
#NoTrayIcon
;#NoEnv



IfNotExist, %A_ScriptDir%\emh_local_info.ini
{
	;FileAppend , #如果您需要修改配置文件的下载地址，可修改Info_File_URL等号之后的内容`n#其余部分请不要改动!!!`n#`n#, %A_ScriptDir%\emh_local_info.ini
	IniWrite, http://emh.googlecode.com/files/emh-example.txt, %A_ScriptDir%\emh_local_info.ini, Setting, Info_File_URL
	IniWrite, 60000, %A_ScriptDir%\emh_local_info.ini, Setting, Wait
	WaitFor=60000
	FileAppend, `n`n===========此线以下不用修改=============`n`n
	;======================================================================	
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Wallpaper, Sleep1_M11_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Wallpaper, Message11_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Wallpaper, Sleep2_M11_L
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Wallpaper, Sleep1_WP_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Wallpaper, Wallpaper_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Wallpaper, Sleep2_WP_L
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Wallpaper, Sleep1_M12_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Wallpaper, Message12_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Wallpaper, Sleep2_M12_L
	;======================================================================
	FileAppend, `n`n`n
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Browser, Sleep1_M21_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Browser, Message21_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Browser, Sleep2_M21_L
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Browser, Sleep1_BW_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Browser, Browser_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Browser, Sleep2_BW_L
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Browser, Sleep1_M22_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Browser, Message22_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Browser, Sleep2_M22_L
	;======================================================================
	FileAppend, `n`n`n
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Audio, Sleep1_M31_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Audio, Message31_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Audio, Sleep2_M31_L
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Audio, Sleep1_AD_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Audio, Audio_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Audio, Sleep2_AD_L
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Audio, Sleep1_M32_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Audio, Message32_L
	IniWrite, "", %A_ScriptDir%\emh_local_info.ini, Audio, Sleep2_M32_L
	;======================================================================	
	Reinput:
	InputBox, Info_File_URL ,电子家信, 请输入配置文件的下载地址, , 350, 150, , , , , http://emh.googlecode.com/files/emh-example.txt
	if ErrorLevel
		{
		MsgBox, 262180, 电子家信, 如果不设定配置文件的下载地址，将不能使用电子家信的功能`n`n现在设定配置文件的下载地址吗？
		IfMsgBox Yes
			Goto,Reinput
		else
			{
			
				run,http://code.google.com/p/emh/
				FileDelete, %A_ScriptDir%\emh_local_info.ini
				
				exit
			}
			
		}
		else
		{
		IniWrite, %Info_File_URL%, %A_ScriptDir%\emh_local_info.ini, Setting, Info_File_URL
		run,http://code.google.com/p/emh/
		
		MsgBox, 262144, 电子家信, 配置文件的下载地址为：%Info_File_URL%`n`n如果要修改下载地址，请打开%A_ScriptDir%\emh_local_info.ini
		MsgBox, 262180, 电子家信, 您想开机自动启动电子家信吗？`n`n这样您的家人就不用手动启动电子家信了，但如果想要更为灵活地使用电子家信，可以使用Windows自带的“任务计划”服务。`n详细设置请访问官网http://code.google.com/p/emh/
			IfMsgBox Yes
			{
			RegWrite, REG_SZ,HKEY_CURRENT_USER,SOFTWARE\Microsoft\Windows\CurrentVersion\Run, EMH, %A_ScriptFullPath%
			}
			else
			{
			MsgBox, 262144, 电子家信, 电子家信现在不能开机自动运行，这意味这您的家人不能看到您在异地发送的消息，请设置“任务计划”服务。详细设置请访问官网http://code.google.com/p/emh/
			}
		
		}
		;MsgBox, You entered "%Info_File_URL%"

}
else
{
	IniRead, Info_File_URL, %A_ScriptDir%\emh_local_info.ini, Setting, Info_File_URL
	IniRead, WaitFor, %A_ScriptDir%\emh_local_info.ini, Setting, Wait
	;======================================================================	
	IniRead, Sleep1_M11_L, %A_ScriptDir%\emh_local_info.ini, Wallpaper, Sleep1_M11_L
	IniRead, Message11_L, %A_ScriptDir%\emh_local_info.ini, Wallpaper, Message11_L
	IniRead, Sleep2_M11_L, %A_ScriptDir%\emh_local_info.ini, Wallpaper, Sleep2_M11_L
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniRead, Sleep1_WP_L, %A_ScriptDir%\emh_local_info.ini, Wallpaper, Sleep1_WP_L
	IniRead, Wallpaper_L, %A_ScriptDir%\emh_local_info.ini, Wallpaper, Wallpaper_L
	IniRead, Sleep2_WP_L, %A_ScriptDir%\emh_local_info.ini, Wallpaper, Sleep2_WP_L
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniRead, Sleep1_M12_L, %A_ScriptDir%\emh_local_info.ini, Wallpaper, Sleep1_M12_L
	IniRead, Message12_L, %A_ScriptDir%\emh_local_info.ini, Wallpaper, Message12_L
	IniRead, Sleep2_M12_L, %A_ScriptDir%\emh_local_info.ini, Wallpaper, Sleep2_M12_L
	;======================================================================
	IniRead, Sleep1_M21_L, %A_ScriptDir%\emh_local_info.ini, Browser, Sleep1_M21_L
	IniRead, Message21_L, %A_ScriptDir%\emh_local_info.ini, Browser, Message21_L
	IniRead, Sleep2_M21_L, %A_ScriptDir%\emh_local_info.ini, Browser, Sleep2_M21_L
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniRead, Sleep1_BW_L, %A_ScriptDir%\emh_local_info.ini, Browser, Sleep1_BW_L
	IniRead, Browser_L, %A_ScriptDir%\emh_local_info.ini, Browser, Browser_L
	IniRead, Sleep2_BW_L, %A_ScriptDir%\emh_local_info.ini, Browser, Sleep2_BW_L
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniRead, Sleep1_M22_L, %A_ScriptDir%\emh_local_info.ini, Browser, Sleep1_M22_L
	IniRead, Message22_L, %A_ScriptDir%\emh_local_info.ini, Browser, Message22_L
	IniRead, Sleep2_M22_L, %A_ScriptDir%\emh_local_info.ini, Browser, Sleep2_M22_L
	;======================================================================
	IniRead, Sleep1_M31_L, %A_ScriptDir%\emh_local_info.ini, Audio, Sleep1_M31_L
	IniRead, Message31_L, %A_ScriptDir%\emh_local_info.ini, Audio, Message31_L
	IniRead, Sleep2_M31_L, %A_ScriptDir%\emh_local_info.ini, Audio, Sleep2_M31_L
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
	IniRead, Sleep1_AD_L, %A_ScriptDir%\emh_local_info.ini, Audio, Sleep1_AD_L
	IniRead, Audio_L, %A_ScriptDir%\emh_local_info.ini, Audio, Audio_L
	IniRead, Sleep2_AD_L, %A_ScriptDir%\emh_local_info.ini, Audio, Sleep2_AD_L
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniRead, Sleep1_M32_L, %A_ScriptDir%\emh_local_info.ini, Audio, Sleep1_M32_L
	IniRead, Message32_L, %A_ScriptDir%\emh_local_info.ini, Audio, Message32_L
	IniRead, Sleep2_M32_L, %A_ScriptDir%\emh_local_info.ini, Audio, Sleep2_M32_L
	;======================================================================	
	;msgbox,Info_File_URL=%Info_File_URL%
}
	
sleep,%WaitFor%

	

ReDownload:	
Sleep,2000
;msgbox,Info_File_URL=%Info_File_URL% will dl
UrlDownloadToFile, %Info_File_URL%, %A_ScriptDir%\emh_online_info.ini
If ErrorLevel=1
	exit
else
{
;msgbox,dl over
	Sleep,2000
	IfNotExist, %A_ScriptDir%\emh_online_info.ini
		Goto,ReDownload
	IniRead, First, %A_ScriptDir%\emh_online_info.ini, Order, First
	IniRead, Second, %A_ScriptDir%\emh_online_info.ini, Order, Second
	IniRead, Third, %A_ScriptDir%\emh_online_info.ini, Order, Third
	;======================================================================	
	IniRead, Sleep1_M11, %A_ScriptDir%\emh_online_info.ini, Wallpaper, Sleep1_M11
	IniRead, Message11, %A_ScriptDir%\emh_online_info.ini, Wallpaper, Message11
	IniRead, Sleep2_M11, %A_ScriptDir%\emh_online_info.ini, Wallpaper, Sleep2_M11
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniRead, Sleep1_WP, %A_ScriptDir%\emh_online_info.ini, Wallpaper, Sleep1_WP
	IniRead, Wallpaper, %A_ScriptDir%\emh_online_info.ini, Wallpaper, Wallpaper
	IniRead, Sleep2_WP, %A_ScriptDir%\emh_online_info.ini, Wallpaper, Sleep2_WP
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniRead, Sleep1_M12, %A_ScriptDir%\emh_online_info.ini, Wallpaper, Sleep1_M12
	IniRead, Message12, %A_ScriptDir%\emh_online_info.ini, Wallpaper, Message12
	IniRead, Sleep2_M12, %A_ScriptDir%\emh_online_info.ini, Wallpaper, Sleep2_M12
	;======================================================================
	IniRead, Sleep1_M21, %A_ScriptDir%\emh_online_info.ini, Browser, Sleep1_M21
	IniRead, Message21, %A_ScriptDir%\emh_online_info.ini, Browser, Message21
	IniRead, Sleep2_M21, %A_ScriptDir%\emh_online_info.ini, Browser, Sleep2_M21
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniRead, Sleep1_BW, %A_ScriptDir%\emh_online_info.ini, Browser, Sleep1_BW
	IniRead, Browser, %A_ScriptDir%\emh_online_info.ini, Browser, Browser
	IniRead, Sleep2_BW, %A_ScriptDir%\emh_online_info.ini, Browser, Sleep2_BW
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniRead, Sleep1_M22, %A_ScriptDir%\emh_online_info.ini, Browser, Sleep1_M22
	IniRead, Message22, %A_ScriptDir%\emh_online_info.ini, Browser, Message22
	IniRead, Sleep2_M22, %A_ScriptDir%\emh_online_info.ini, Browser, Sleep2_M22
	;======================================================================
	IniRead, Sleep1_M31, %A_ScriptDir%\emh_online_info.ini, Audio, Sleep1_M31
	IniRead, Message31, %A_ScriptDir%\emh_online_info.ini, Audio, Message31
	IniRead, Sleep2_M31, %A_ScriptDir%\emh_online_info.ini, Audio, Sleep2_M31
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
	IniRead, Sleep1_AD, %A_ScriptDir%\emh_online_info.ini, Audio, Sleep1_AD
	IniRead, Audio, %A_ScriptDir%\emh_online_info.ini, Audio, Audio
	IniRead, Sleep2_AD, %A_ScriptDir%\emh_online_info.ini, Audio, Sleep2_AD
	;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	IniRead, Sleep1_M32, %A_ScriptDir%\emh_online_info.ini, Audio, Sleep1_M32
	IniRead, Message32, %A_ScriptDir%\emh_online_info.ini, Audio, Message32
	IniRead, Sleep2_M32, %A_ScriptDir%\emh_online_info.ini, Audio, Sleep2_M32
	;======================================================================	
	Sleep,2000
	FileDelete, %A_ScriptDir%\emh_online_info.ini
	;msgbox,%Wallpaper%=%Wallpaper_L%`n%Message11%=%Message11_L%`n%Message21%=%Message21%`n%Message31%=%Message31_L%`n%Browser%=%Browser_L%`n%Audio%=%Audio_L%
	If ((Message11=Message11_L)&&(Wallpaper=Wallpaper_L)&&(Message12=Message12_L)&&(Message21=Message21_L)&&(Browser=Browser_L)(Message22=Message22_L)&&(Message31=Message31_L)&&(Audio=Audio_L)&&(Message32=Message32_L))
	{
		;msgbox,no need
		exit
	}
	else
	{
		If (Wallpaper<>Wallpaper_L)
		{
		W_Need=1
		IfNotExist, %A_ScriptDir%\emh_Wallpapers\
			FileCreateDir, %A_ScriptDir%\emh_Wallpapers\
		Sleep,2000
		FormatTime, CurrentDateTime,, yyyy-MM-dd[HH.mm.ss]
		WPDir=%A_ScriptDir%\emh_Wallpapers\%CurrentDateTime%.jpg
		;msgbox,NewWPDir=%A_ScriptDir%\emh_Wallpapers\%CurrentDateTime%.jpg
		ReDownWallpaper:
		UrlDownloadToFile, %Wallpaper%, %WPDir%
		sleep,5000
		If ErrorLevel=1
			Goto,ReDownWallpaper
		
		}
		
		If (Audio<>Audio_L)
		{
		IfNotExist, %A_ScriptDir%\emh_Audio\
			FileCreateDir, %A_ScriptDir%\emh_Audio\
		Sleep,2000
		FormatTime, CurrentDateTime,, yyyy-MM-dd[HH.mm.ss]
		ADDir=%A_ScriptDir%\emh_Audio\%CurrentDateTime%.wav
		;msgbox,NewWPDir=%A_ScriptDir%\emh_Audio\%CurrentDateTime%.wav
		ReDownAudio:
		UrlDownloadToFile, %Audio%, %ADDir%
		sleep,5000
		If ErrorLevel=1
			Goto,ReDownAudio
		IniWrite, %Audio%, emh_local_info.ini, Audio, Audio_L
		}
		else
		{
			IniRead, ADDir, %A_ScriptDir%\emh_local_info.ini, Audio, Audio_Last_Dir
		}
	
		Gosub,JumpTo
	}




}

JumpTo:
{
UrlDownloadToFile, http://emh.googlecode.com/files/emh-counter.txt, %A_ScriptDir%\emh-counter.txt
sleep,2000
FileDelete, %A_ScriptDir%\emh-counter.txt
	If(First="W" and W_Need=1)
		GoSub,Change_Wallpaper		
	If(First="B")
		GoSub,Open_Browser		
	If(First="A")
		GoSub,Play_Audio		

	If(Second="W" and W_Need=1)
		GoSub,Change_Wallpaper		
	If(Second="B")
		GoSub,Open_Browser		
	If(Second="A")
		GoSub,Play_Audio		
		
	If(Third="W" and W_Need=1)
		GoSub,Change_Wallpaper
	If(Third="B")
		GoSub,Open_Browser		
	If(Third="A")
		GoSub,Play_Audio
		
	sleep,5000	
	If (W_Need=1)
	{
		RegWrite, REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoDesktop,0
		sleep,3000
		send,#m
		sleep,2000
		Process, Close, explorer.exe
		
	}
exit
}
return





	
	
Change_Wallpaper:
fn_Message_with_Sleep(11,"Wallpaper")
		Sleep,1000
		RegWrite, REG_SZ,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System, Wallpaper, %WPDir%
		RegWrite, REG_SZ,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System, WallpaperStyle, 4
		RegWrite, REG_DWORD,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System, NoDispBackgroundPage,1
		RegWrite, REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Policies\Explorer, NoDesktop,1
		DllCall("SystemParametersInfo", UInt, 0x14, UInt, 0, Str, WPDir, UInt, 2)

		sleep,2000
		Process, Close, explorer.exe
		sleep,3000
		send,#m
		sleep,3000
		IniWrite, %Wallpaper%, emh_local_info.ini, Wallpaper, Wallpaper_L
		
fn_Message_with_Sleep(12,"Wallpaper")

return
	
Open_Browser:
fn_Message_with_Sleep(21,"Browser")
	Run,%Browser%
	IniWrite, %Browser%, emh_local_info.ini, Browser, Browser_L
fn_Message_with_Sleep(22,"Browser")
return
	
Play_Audio:
fn_Message_with_Sleep(31,"Audio")
		;msgbox,ADDir==%ADDir%
		SoundPlay, %ADDir%		
		IniWrite, %ADDir%, emh_local_info.ini, Audio, Audio_Last_Dir
fn_Message_with_Sleep(32,"Audio")
return



fn_Message_with_Sleep(ThePlace,Category)
{
MessageContext:=Message%ThePlace%
If (MessageContext="")
	return

Sleep1Time:=Sleep1_M%ThePlace%
Sleep2Time:=Sleep2_M%ThePlace%

	If ((Sleep1Time<>"") && (Sleep1Time<>0))
		sleep,%Sleep1Time%
	MsgBox, 262144, 电子家信,%MessageContext%	
	IniWrite, %MessageContext%, emh_local_info.ini, %Category%, Message%ThePlace%_L
	If ((Sleep2Time<>"") && (Sleep2Time<>0))
		sleep,%Sleep2Time%
return
}